{extend name="shop/new/base" /}
{block name="head"}
<!--头部-->
<div class="header shopHeader">
    <div class="w w1200 clearfix">

        <div class="fl oneItem">
            <div class="logo">
                <a href="{:__URL('SHOP_MAIN')}" class="logo_a"><img src="{:__IMG($pc_info['logo'])}" alt=""></a>
            </div>
        </div>

        <div class="stepbar-box step3"></div>

    </div>
</div>
<!--分隔线-->
<div class="sc-hr"></div>
{/block}
{block name="main"}
<!--订单提示-->
<div class="order-init w1000 clearfix">
    <div class="fl o-left">请在<span class="red J-orderTime">00:00:00</span>内完成支付，否则订单会被自动关闭</div>
    <div class="fr o-right">待支付：<span class="red">￥{$pay_value.pay_money}</span></div>
</div>
<!--微信支付-->
<div class="w1000 pay-weixin" style="margin-bottom:10px;">
    <div class="p-w-hd">微信支付</div>
    <div class="p-w-bd clearfix">
        <div class="p-w-box">
            <div class="pw-box-hd" id="J-wechatUrl">
                <img src="{:__IMG($path)}" alt="">
            </div>
            <div class="pw-box-ft">
                <p>请使用微信扫一扫</p>
                <p>扫描二维码支付</p>
            </div>
            <div class="p-w-message J-weixinInfo">
                （二维码将在<span class="red J-qrCodeTime">45</span>秒后刷新）
            </div>
        </div>
        <div class="p-w-sidebar"></div>
        <input type="hidden" value="{$pay_value.create_time | getTimeStampTurnTime}" id="create_time" />
        <input type="hidden" value="{$shop_config['order_buy_close_time']}" id="buy_close_time" />
        <input type="hidden" value="{$pay_value['out_trade_no']}" id="out_trade_no" />
    </div>
    <div class="p-w-hd"><a href="javascript:history.go(-1);" class="blue"><选择其他支付</a></div>
</div>
{/block}
{block name="javascript"}
<script>
    require(['pay'], function (pay) {
        pay.wechat();
        pay.operation();
        var interval = null;
        countdown();
        interval = setInterval("countdown()", 1000);
        var payStatus = window.setInterval("payStatu()", 2000);

    });
    function wchatOverdue() {
        var time = parseInt($(".J-qrCodeTime").text());
        if (time != 0) {
            $(".J-qrCodeTime").text(--time);
        } else {
            location.reload();
            $(".J-weixinInfo").html("<span class='red'>二维码已过期</span>，请刷新页面重新获取二维码。");
            $("#J-wechatUrl img").attr("src", "");
        }
    }
    function payStatu() {
        $.ajax({
            type: "post",
            url: "{:__URL('SHOP_MAIN/pay/wchatQrcodePay')}",
            data: {
                out_trade_no: "{$pay_value.out_trade_no}"
            },
            success: function (data) {
                if (data['code'] > 0) {
                    location.href = "{:__URL('SHOP_MAIN/pay/wchatPayResult&out_trade_no='.$pay_value['out_trade_no'].'&msg=1')}";
                    clearInterval(payStatus);
                }
            }
        })
    }
    function countdown() {
        var date = new Date($("#create_time").val().replace(/\-/g, "\/"));//订单创建时间
        var buy_close_time = parseFloat($("#buy_close_time").val()) * 60 * 1000;//订单关闭时间
        date.setDate(date.getDate() + 1);
        var date_now = new Date($.ajax({async: false}).getResponseHeader("Date"));//当前时间
        var end_time = date.getTime() + buy_close_time; //结束时间毫秒数
        var lag = (end_time - date_now.getTime()) / 1000; //当前时间和结束时间之间的秒数 
        if (lag > 0) {
            var hour = Math.floor((lag / 3600) % 24);
            var minute = Math.floor((lag / 60) % 60);
            var second = Math.floor(lag % 60);
            if (hour == 0 && second == 0 && minute == 0) {
                clearInterval(interval);
                window.history.go(-1);
            }
            if (second < 10) {
                second = "0" + second;
            }
            if (minute < 10) {
                minute = "0" + minute;
            }
            if (hour < 10) {
                hour = "0" + hour;
            }
            $(".J-orderTime").text(hour + ":" + minute + ":" + second);
        }
    }

</script>
{/block}